package com.soul.sort;

import java.util.Arrays;

/**
 * 测试排序算法
 */
public class SortApp {
    static boolean printa = true;
    public static void main(String[] args) {

        int[] a = new int[]{0,8,7,6,5,3,4,2,1,9};

        int[] a1 = shellSort(a);
        int[] a2 = insertionSort(a);
        int[] a3 = selectionSort(a);
        int[] a4 = heapSort(a);
        int[] a5 = bubbleSort(a);
        int[] a6 = mergeSort(a);
        int[] a7 = quickSort(a);
        int[] a8 = basedSort(a);
    }


    public static int[] basedSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        BasedSort.sort(ints);//基数
        System.out.println("基数:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("基数:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] quickSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        QuickSort.sort(ints);//快速
        System.out.println("快速:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("快速:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] mergeSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        MergeSort.sort(ints);//归并
        System.out.println("归并:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("归并:"+Arrays.toString(ints));
        return ints;
    }


    public static int[] bubbleSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        BubbleSort.sort(ints);//冒泡
        System.out.println("冒泡:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("冒泡:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] insertionSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        InsertionSort.sort(ints);//插入
        System.out.println("插入:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("插入:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] shellSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        ShellSort.sort(ints);//希尔
        System.out.println("希尔:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("希尔:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] selectionSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        SelectionSort.sort(ints);//选择
        System.out.println("选择:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("选择:"+Arrays.toString(ints));
        return ints;
    }

    public static int[] heapSort(int[] a){
        int[] ints = Arrays.copyOf(a, a.length);
        long s = System.currentTimeMillis();
        HeapSort.sort(ints);//堆
        System.out.println("堆:"+(System.currentTimeMillis() - s));
        if(printa)System.out.println("堆:"+Arrays.toString(ints));
        return ints;
    }
}
